package org.tp8.sampleapp.service;

import java.io.Serializable;

import javax.jws.WebParam;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.tp8.sampleapp.dms.model.AbstractDocModel;
import org.tp8.sampleapp.exc.SampleAppException;
import org.tp8.sampleapp.jaxb.paging.adapter.PageableAdapter;
import org.tp8.sampleapp.rule.model.RuleModelWrapper;

/**
 * The Interface BaseEntityService.
 * 
 * @param <K>
 *            the key type
 * @param <T>
 *            the generic type
 */
public interface BaseDocService<K extends Serializable, T extends AbstractDocModel<K>>
		extends BaseService, Serializable {

	/**
	 * Save.
	 * 
	 * @param t
	 *            the t
	 * @return the t
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public String save(T t) throws SampleAppException;

	/**
	 * Delete.
	 * 
	 * @param id
	 *            the id
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public void delete(K id) throws SampleAppException;

	/**
	 * Find one.
	 * 
	 * @param id
	 *            the id
	 * @return the t
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public T findOne(K id) throws SampleAppException;

	/**
	 * Find attachment.
	 * 
	 * @param id
	 *            the id
	 * @return the byte[]
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public byte[] findAttachment(K id) throws SampleAppException;

	/**
	 * Find metadata.
	 * 
	 * @param id
	 *            the id
	 * @return the t
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public T findMetadata(K id) throws SampleAppException;

	/**
	 * Find all.
	 * 
	 * @param pageable
	 *            the pageable
	 * @return the page
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public Page<T> findAll(
			@XmlJavaTypeAdapter(PageableAdapter.class) @WebParam(name = "pageable") Pageable pageable)
			throws SampleAppException;

	/**
	 * Validate.
	 * 
	 * @param t
	 *            the t
	 * @return the rule model wrapper
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public RuleModelWrapper validate(T t) throws SampleAppException;

	/**
	 * Count.
	 * 
	 * @return the long
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public long count() throws SampleAppException;

}
